package com.wee.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.bigtotoro.UILImageLoader;
import com.bigtotoro.widgets.listview.HorizontalListView;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.wee.aircoach_user.R;
import com.wee.entity.Coach_list;
import com.wee.entity.TrainDetails;
import com.wee.fragment.find.StsAdapter;

import java.util.List;

/**
 * Created by xiaobing on 15/7/26.
 */
public class CoachAdapter1 extends BaseAdapter {
    private Context context;
    private List<TrainDetails> data1;
    private DisplayImageOptions options;
    private List<TrainDetails.DataBean> dataBeans;
    private StsAdapter stsadapter;

    public CoachAdapter1(Context context,  List<TrainDetails.DataBean> dataBeans) {
        this.context = context;
        this.dataBeans = dataBeans;
        options = new DisplayImageOptions.Builder()
                .showImageOnLoading(R.drawable.find_nocoach)
                .showImageForEmptyUri(R.drawable.find_nocoach)
                .showImageOnFail(R.drawable.find_nocoach)
                .cacheInMemory(true)
                .cacheOnDisk(true)
                .considerExifParams(true)
                        //.displayer(new RoundedBitmapDisplayer(Color.WHITE, 5))
                .build();
        UILImageLoader.initImageLoader(context.getApplicationContext());

    }

    @Override
    public int getCount() {
        return dataBeans.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder ;
        if(convertView==null){
            holder = new ViewHolder();
            LayoutInflater inflate = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflate.inflate(R.layout.item_coacha, null);
            holder.img = (ImageView)convertView.findViewById(R.id.photo);
            holder.gener = (TextView)convertView.findViewById(R.id.gener);
            holder.name = (TextView)convertView.findViewById(R.id.name);
            holder.ski = (TextView)convertView.findViewById(R.id.ski);
            holder.skill = (TextView)convertView.findViewById(R.id.skill);
            holder.list_find= (ListView) convertView.findViewById(R.id.list_find);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder)convertView.getTag();
        }
        //TrainDetails details = data1.get(position);
        TrainDetails.DataBean dataBean = dataBeans.get(position);

        stsadapter = new StsAdapter(context, dataBean.getImage());
        holder.list_find.setAdapter(stsadapter);
       /* holder.listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Actions actions1 =actionlist.getActions().get(position);
                ((WarmActionActivity) context).returnToPlanActivity(actions1);
            }
        });*/
        ImageLoader.getInstance().displayImage(dataBean.getFigure(), holder.img, options);
        holder.name.getPaint().setFakeBoldText(true);
        holder.name.setText("" + dataBean.getName());
        holder.ski.setText(""+dataBean.getDiscription());
        holder.skill.setText(""+dataBean.getTitle());

        if(dataBean.getGender()!=null){
            if(dataBean.getGender().equals("male")){
                holder.gener.setText("男");
            }else{
                holder.gener.setText("女");
            }
        }
        holder.ski.setText("专业的运动员 特技专业私人教练");
      //  holder.skill.setText("擅长："+coach_list.getDiscription());


        return convertView;
    }

    static class ViewHolder{
        ImageView img;
        TextView name, ski, gener,skill;
        ListView list_find;
    }
}
